/*
 * Copyright (C) 2011 Jesus Navalon i Pastor <jnavalon at redhermes dot net>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/*
 * pn_Allocate.java
 *
 * Created on 25/08/2011, 11:49:35
 */
package kuasar.plugin.deployer.gui;

import javax.swing.JPanel;
import kuasar.plugin.Intercom.GUI;
import kuasar.plugin.deployer.gui.classmod.I_Panels;
import org.jdom.Element;

/**
 *
 * @author Jesus Navalon i Pastor <jnavalon at redhermes dot net>
 */
public class pn_Strategy extends kuasar.plugin.classMod.AbstractPanel implements I_Panels{
    private JPanel previous;
    private boolean ramfirst=false;
    private Element servers;
    private Element vms;
    /** Creates new form pn_Allocate */
    public pn_Strategy(Element vms, Element servers, JPanel previous) {
        this.previous=previous;
        this.servers = servers;
        this.vms = vms;
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        pn_Sub = new javax.swing.JPanel();
        btn_Back = new javax.swing.JButton();
        Title = new javax.swing.JLabel();
        pn_Cont = new javax.swing.JPanel();
        btn_space = new javax.swing.JButton();
        pn_left = new javax.swing.JPanel();
        pn_right = new javax.swing.JPanel();
        btn_ram = new javax.swing.JButton();
        pn_down = new javax.swing.JPanel();
        pn_up = new javax.swing.JPanel();

        setOpaque(false);

        pn_Sub.setOpaque(false);

        btn_Back.setBackground(new java.awt.Color(0, 0, 0));
        btn_Back.setForeground(new java.awt.Color(204, 204, 204));
        btn_Back.setIcon(new javax.swing.ImageIcon(getClass().getResource("/kuasar/plugin/deployer/icons/previous22.png"))); // NOI18N
        btn_Back.setText("Back");
        btn_Back.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        btn_Back.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_BackActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout pn_SubLayout = new javax.swing.GroupLayout(pn_Sub);
        pn_Sub.setLayout(pn_SubLayout);
        pn_SubLayout.setHorizontalGroup(
            pn_SubLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pn_SubLayout.createSequentialGroup()
                .addContainerGap(405, Short.MAX_VALUE)
                .addComponent(btn_Back)
                .addContainerGap())
        );
        pn_SubLayout.setVerticalGroup(
            pn_SubLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(btn_Back)
        );

        Title.setFont(new java.awt.Font("Dialog", 1, 28));
        Title.setForeground(new java.awt.Color(204, 204, 204));
        Title.setIcon(new javax.swing.ImageIcon(getClass().getResource("/kuasar/plugin/deployer/icons/strategy48.png"))); // NOI18N
        Title.setText("Select Strategy");

        pn_Cont.setOpaque(false);

        btn_space.setBackground(new java.awt.Color(0, 0, 0));
        btn_space.setFont(new java.awt.Font("Dialog", 0, 18)); // NOI18N
        btn_space.setForeground(new java.awt.Color(204, 204, 204));
        btn_space.setIcon(new javax.swing.ImageIcon(getClass().getResource("/kuasar/plugin/deployer/icons/space48.png"))); // NOI18N
        btn_space.setText("Space First");
        btn_space.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        btn_space.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_spaceActionPerformed(evt);
            }
        });

        pn_left.setOpaque(false);

        javax.swing.GroupLayout pn_leftLayout = new javax.swing.GroupLayout(pn_left);
        pn_left.setLayout(pn_leftLayout);
        pn_leftLayout.setHorizontalGroup(
            pn_leftLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 65, Short.MAX_VALUE)
        );
        pn_leftLayout.setVerticalGroup(
            pn_leftLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 238, Short.MAX_VALUE)
        );

        pn_right.setOpaque(false);

        javax.swing.GroupLayout pn_rightLayout = new javax.swing.GroupLayout(pn_right);
        pn_right.setLayout(pn_rightLayout);
        pn_rightLayout.setHorizontalGroup(
            pn_rightLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 65, Short.MAX_VALUE)
        );
        pn_rightLayout.setVerticalGroup(
            pn_rightLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 238, Short.MAX_VALUE)
        );

        btn_ram.setBackground(new java.awt.Color(0, 0, 0));
        btn_ram.setFont(new java.awt.Font("Dialog", 0, 18)); // NOI18N
        btn_ram.setForeground(new java.awt.Color(204, 204, 204));
        btn_ram.setIcon(new javax.swing.ImageIcon(getClass().getResource("/kuasar/plugin/deployer/icons/mem48.png"))); // NOI18N
        btn_ram.setText("RAM First");
        btn_ram.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        btn_ram.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_ramActionPerformed(evt);
            }
        });

        pn_down.setOpaque(false);

        javax.swing.GroupLayout pn_downLayout = new javax.swing.GroupLayout(pn_down);
        pn_down.setLayout(pn_downLayout);
        pn_downLayout.setHorizontalGroup(
            pn_downLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 364, Short.MAX_VALUE)
        );
        pn_downLayout.setVerticalGroup(
            pn_downLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 62, Short.MAX_VALUE)
        );

        pn_up.setOpaque(false);

        javax.swing.GroupLayout pn_upLayout = new javax.swing.GroupLayout(pn_up);
        pn_up.setLayout(pn_upLayout);
        pn_upLayout.setHorizontalGroup(
            pn_upLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 364, Short.MAX_VALUE)
        );
        pn_upLayout.setVerticalGroup(
            pn_upLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 41, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout pn_ContLayout = new javax.swing.GroupLayout(pn_Cont);
        pn_Cont.setLayout(pn_ContLayout);
        pn_ContLayout.setHorizontalGroup(
            pn_ContLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pn_ContLayout.createSequentialGroup()
                .addComponent(pn_left, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pn_ContLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(pn_up, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(pn_down, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btn_ram, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 364, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btn_space, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 364, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(pn_right, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        pn_ContLayout.setVerticalGroup(
            pn_ContLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(pn_left, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(pn_right, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(pn_ContLayout.createSequentialGroup()
                .addComponent(pn_up, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btn_space)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btn_ram, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(pn_down, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(pn_Cont, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(pn_Sub, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(Title, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 506, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(Title, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(pn_Cont, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(pn_Sub, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

private void btn_BackActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_BackActionPerformed
      goPrevious();
}//GEN-LAST:event_btn_BackActionPerformed

private void btn_spaceActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_spaceActionPerformed
    ramfirst=false;
    goNext();
}//GEN-LAST:event_btn_spaceActionPerformed

private void btn_ramActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_ramActionPerformed
    ramfirst=true;
    goNext();
}//GEN-LAST:event_btn_ramActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel Title;
    private javax.swing.JButton btn_Back;
    private javax.swing.JButton btn_ram;
    private javax.swing.JButton btn_space;
    private javax.swing.JPanel pn_Cont;
    private javax.swing.JPanel pn_Sub;
    private javax.swing.JPanel pn_down;
    private javax.swing.JPanel pn_left;
    private javax.swing.JPanel pn_right;
    private javax.swing.JPanel pn_up;
    // End of variables declaration//GEN-END:variables


    @Override
    public void goNext() {
        pn_Allocating alloc = new pn_Allocating(vms, servers,ramfirst, previous, this);
        GUI.loadPlugin(alloc);
        GUI.updateUI();
        alloc.startScanning();
    }

    @Override
    public void goPrevious() {
        GUI.loadPlugin(previous);
        GUI.updateUI();
    }
}
